﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.ModelConfiguration;
using Training.Dia1.Data.Entities;

namespace Training.Dia1.Data.Mappings
{
    public class ProductMap : EntityTypeConfiguration<Product>
    {
        public ProductMap()
        {
            //table
            ToTable("Products");

            //pk
            HasKey(t => t.Id);

            //property
            Property(t => t.Id)
                .HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity);
            Property(t => t.Name)
                .IsRequired();

            //relationship
            HasRequired(t => t.MeasureUnit)
                .WithMany(c => c.Products)
                .HasForeignKey(t => t.MeasureUnitId)
                .WillCascadeOnDelete(false);

        }
    }
}
